/*********************************************************************
Replication Materials for "Explanation Giving Promotes Democratic Satisfaction Regardless of Respondent Partisanship"

Syntax produces the models discussed in Online Appendix C, Table OC1. 
The syntax also produces the output that will be plotted in Figure OC1 (via an R syntax file). 
***********************************************************************/

/*******************
Working Directory and Data
Update working directory to where you have the data
********************/

cd "C:\Users\jar68\OneDrive\Ongoing Work\Explanations and Dem Support\P. Behavior\Revision\R2\RR3\FINAL\Dataverse\"
use "ess_final.dta"

**Dropping non-democracies; Bulgaria had caretaker gov't
drop if country == "Albania" | country == "Russia" | country == "Kosovo" | country == "Ukraine" | country == "Bulgaria"

/*********************************
Weights
*********************************/

gen anweight = pspwght*pweight
label var anweight "Analysis Weight"

/*********************************
Models & Table OC1
*********************************/

***Models

eststo clear
local conts " std_courts std_elections std_econ std_life std_socialtrust i.ideol_ext1 std_ladder std_educ c.age i.gender i.minority i.citizen i.east_europe c.enep_comb c.unemp_ch"
	eststo: mixed trust_politicians std_explains reason_std [pweight=anweight] || country:  
			margins, at(std_explains=(-2(1)2)) saving(tpol_explain_pred_m1, replace)
			margins, at(reason_std=(-2(1)2)) saving(tpol_reason_pred_m1, replace)
	eststo: mixed trust_politicians std_explains reason_std i.co_partisan `conts'  [pweight=anweight] || country: 
			margins, at(std_explains=(-2(1)2)) saving(tpol_explain_pred_m2, replace)
			margins, at(reason_std=(-2(1)2)) saving(tpol_reason_pred_m2, replace)
	eststo: mixed trust_politicians c.std_explains##i.co_partisan c.reason_std##i.co_partisan `conts' [pweight=anweight] || country: 
			*explains * co-partisanship
				margins, dydx(std_explains) by(co_partisan) saving(tpol_explain_dydx_m3, replace)
				margins, dydx(co_partisan) at(std_explains=(-2(1)2)) saving(tpol_cop_explain_dydx_m3, replace)
				margins co_partisan, at(std_explains=(-2(1)2)) saving(tpol_explain_pred_m3, replace)
			*reasons * co-partisanship
				margins, dydx(reason_std) by(co_partisan) saving(tpol_reason_dydx_m3, replace)
				margins, dydx(co_partisan) at(reason_std=(-2(1)2)) saving(tpol_cop_reason_dydx_m3, replace)
				margins co_partisan, at(reason_std=(-2(1)2)) saving(tpol_reason_pred_m3, replace)


***Table OC1
esttab using table_oc1.rtf, label onecell replace se b(3) aic bic nobaselevels ///
		transform(ln*: exp(2*@) 2*exp(2*@)) ///
		eqlabels("" "var(Constant)" "var(Residual)", none) ///
		title("{\b Table OC1}: Explanation Giving and Trust in Politicians") ///
		addnotes("DV ranges from 0-10. All continuous variables are country-standardized save for age in years. Analyses use survey weights.")

